package com.collectionAndMap.collection;

import java.lang.reflect.Array;
import java.util.*;

/***
 * @ClassName: ToolCollection
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 14:55 2022/2/18
 * @version : V1.0
 */
public class ToolCollection {
    public static void main(String[] args) {
        Integer [] ints = {1,2,45,56,23,65,12,5,23,54};
        //数组转集合，必须使用ArrayList的有参构造方法，不然会报错,首先集合
        List<Integer> integers = new ArrayList<>(Arrays.asList(ints));
        //集合转数组
        Integer[] integers1 = integers.toArray(new Integer[0]);
        System.out.println(Arrays.toString(integers1));

        Iterator<Integer> iterator = integers.iterator();
        while (iterator.hasNext()) {
            System.out.print(iterator.next()+"\t");
        }
        //反转
        System.out.println();
        Collections.reverse(integers);
        for (Integer integer : integers) {
            System.out.print(integer+"\t");
        }
        //排序
        System.out.println();
        Collections.sort(integers);
        for (Integer integer : integers) {
            System.out.print(integer+"\t");
        }
        System.out.println();
        //二分查找
        int i = Collections.binarySearch(integers, 12);
        System.out.println(i);
        //shuffle打乱
        Collections.shuffle(integers);
        for (Integer integer : integers) {
            System.out.print(integer+"\t");
        }
        System.out.println();
    }
}
